package com.xlh.enums.courseTest;

import com.google.common.collect.Maps;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Map;

/**
 * @author zhr 2019/3/11
 */
@Getter
@AllArgsConstructor
public enum JudgementEnum {
    YES(1, true, "正确"),
    NO(0, false, "错误");

    private final Integer value;
    private final Boolean flag;
    private final String message;

    private static Map<Integer, JudgementEnum> valueLookup = Maps.newHashMap();
    private static Map<String, JudgementEnum> messageLookup = Maps.newHashMap();

    static {
        for (JudgementEnum en : JudgementEnum.values()) {
            valueLookup.put(en.getValue(), en);
            messageLookup.put(en.getMessage(), en);
        }
    }

    public static JudgementEnum forCode(Integer value) {
        return valueLookup.get(value);
    }

    public static JudgementEnum forMessage(String message) {
        return messageLookup.get(message);
    }
}
